package com.cxg.allsys.adminsys.controller;


import com.cxg.allsys.adminsys.service.IMemberService;
import com.cxg.allsys.adminsys.pojo.Member;
import com.cxg.allsys.adminsys.view.PageInfo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Data
@RestController
@RequestMapping("/api")
@CrossOrigin
public class MapperController {

    @Autowired
    private IMemberService memberService;


    @RequestMapping("/Administration/UpdateMemberForEditStatus")
    public String updateMemberForEditStatus(Integer memid,String auditBy,String status){
        log.info("修改数据controller数据执行");
        log.info(status+"---------------"+memid);
        log.info("************"+status);
        boolean qj=memberService.updateStatus(memid,auditBy,status);
        if (qj){
            return "重置成功";
        }
        else {
            return "重置失败";
        }

    }

    //分页查询
    @RequestMapping("/Administration/pViewPageTMember")
    public PageInfo query(PageInfo<Member> pageInfo){
        log.info("分页查询controller执行");
        log.info(pageInfo.getQueryStr()+pageInfo.getPageSize()+pageInfo.getPageIndex());
        List<Member> list=memberService.query(pageInfo.getPageIndex(),pageInfo.getPageSize(),pageInfo.getQueryStr());
        pageInfo.setList(list);
        return pageInfo;
    }


    //添加会员
    @RequestMapping("/Administration/AddMember")
    public String save(Member member){
        log.info("添加数据controller执行");
        log.info("输入内容打印"+member.toString());
        boolean flag=memberService.save(member);
        log.info(String.valueOf(flag));
        log.info("输入内容打印"+member.toString());
        if (flag) {
            return "insertSucc添加成功！";
        } else {
            return "insertFail添加失败！";
        }
    }


    //删除会员
    @RequestMapping("/Administration/DelectMember")
    public String delectMember(Member member){
        log.info("添加数据controller执行");
        boolean flag=memberService.deleteMember(member);
        log.info(String.valueOf(flag));
        log.info("输入内容打印："+member.toString());
        if (flag) {
            return "删除成功！";
        } else {
            return "删除失败！";
        }
    }

}
